<style>
    .avatar {
        width: 28px;
        height: 28px;
        border-radius: 50%;
    }
</style>
<div class="widget-head" style="margin-top:0;">
    <div class="widget-title">日志列表</div>
</div>
<div class="layui-clear">
    <form method="GET" action="/admin/welcome/log" class="fr layui-form" style="width:400px;">
        <div class="layui-input-inline fl" style="width:100px;">
            <php>$types = ['log'=>'日志','realname'=>'姓名'];</php>
            <select name="searchtype">
                <foreach name="types" item="vo" key="k">
                    <option value="{$k}" <if condition="$_GET['searchtype'] eq $k">selected</if>>{$vo}</option>
                </foreach>
            </select>
        </div>
        <div class="layui-input-inline fr" style="width:300px;">
            <button class="layui-btn fr" lay-submit>搜索</button>
            <input type="text" class="layui-input fr" style="width:230px;" name="keywords" placeholder="请输入关键词" value="{$_GET['keywords']}">
        </div>
        <php> $condition = $_GET['searchtype'] && $_GET['keywords'] ? "/searchtype/".$_GET['searchtype']."/keywords/".$_GET['keywords'] : '';</php>
        <script>
            var condition = '{$condition}';
        </script>
    </form>
</div>
<table id="list"></table>

<script>
    layui.use(['think'], function() {
        var think = layui.think;
        //第一个实例
        think.render({
            elem: '#list',
            // height: 500,
            url: "/api/log/getdata" + condition,
            toolbar: true,
            page: true,
            cols: [
                [ //表头
                    {
                        type: 'checkbox',
                        fixed: 'left'
                    }, {
                        field: 'id',
                        title: 'ID',
                        width: 80,
                    }, {
                        field: 'realname',
                        title: '姓名'
                    }, {
                        field: 'avatar',
                        title: '头像',
                        templet: function(d) {
                            if (d['avatar'] == '') {
                                d['avatar'] = '/Public/common/img/avatar.png';
                            }
                            return '<img src="' + d['avatar'] + '" class="avatar">';
                        }
                    }, {
                        field: 'log',
                        title: '日志'
                    }, {
                        field: 'create_time',
                        title: '时间',
                        width: 177,
                        templet: function(d) {
                            return think_time(d.create_time, 'Y-m-d H:i:s'); //think_time()是think.js里面的方法
                        }
                    }
                ]
            ]
        }, '{$_GET["searchtype"]}', '{$_GET["keywords"]}');
    });
</script>